﻿using VGTimer.Common;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevExpress.Mvvm;

namespace VGTimer.Models
{
    public class ConfigInfo
    {
        static ConfigInfo()
        {
            try
            {
                instance = JsonHelper.Instance.DeserializeObjectFroFile<ConfigInfo>(".\\Config\\config.json");
            }
            catch (Exception)
            {
            }

            if (instance == null)
            {
                instance = new ConfigInfo();
            }
        }

        private static ConfigInfo instance;

        public static ConfigInfo Instance
        {
            get { return instance; }
            set { instance = value; }
        }

        public ConfigInfo()
        {
            AllDevices = new ObservableCollection<Device>();
        }

        public ObservableCollection<Device> AllDevices { get; set; }

        /// <summary>
        /// 保存配置
        /// </summary>
        public static void SaveConfig()
        {
            JsonHelper.Instance.SerializeObjectToFile(instance, ".\\Config\\config.json");
            Messenger.Default.Send(true, "1");
        }
    }
}
